package org.hl7.fhir.r5.test.profiles.codegen;

import java.util.List;
import java.util.ArrayList;
import javax.annotation.Nullable;
import java.util.Date;


import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.profilemodel.PEBuilder;
import org.hl7.fhir.r5.profilemodel.PEInstance;
import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
import org.hl7.fhir.r5.profilemodel.gen.PEGeneratedBase;
import org.hl7.fhir.r5.profilemodel.gen.Min;
import org.hl7.fhir.r5.profilemodel.gen.Max;
import org.hl7.fhir.r5.profilemodel.gen.Label;
import org.hl7.fhir.r5.profilemodel.gen.Doco;
import org.hl7.fhir.r5.profilemodel.gen.BindingStrength;
import org.hl7.fhir.r5.profilemodel.gen.ValueSet;
import org.hl7.fhir.r5.profilemodel.gen.MustSupport;
import org.hl7.fhir.r5.profilemodel.gen.Definition;


// Generated by the HAPI Java Profile Generator, 5/11/24, 6:00 pm

/**
 * A formally or informally recognized grouping of people or organizations formed 
 * for the purpose of achieving some form of collective action.  Includes 
 * companies, institutions, corporations, departments, community groups, healthcare 
 * practice groups, payer/insurer, etc.
 *
 */
public class DkCoreOrganization extends PEGeneratedBase {

  public static final String CANONICAL_URL = "http://hl7.dk/fhir/core/StructureDefinition/dk-core-organization|3.2.0";

  @Min("0") @Max("1") @Doco("")
  private String id;  // 

  @Min("0") @Max("*") @Doco("Additional content defined by implementations")
  @Definition("May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.")
  private List<Extension> extensions = new ArrayList<>();  // Additional content defined by implementations

  @Min("0") @Max("*") @Doco("Extensions that cannot be ignored")
  @Definition("May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and manageable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.\n\nModifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).")
  private List<Extension> modifierExtensions = new ArrayList<>();  // Extensions that cannot be ignored

  @Min("1") @Max("*") @Doco("Identifies this organization  across multiple systems")
  @Definition("Identifier for the organization that is used to identify the organization across multiple disparate systems.")
  private List<Identifier> identifiers = new ArrayList<>();// @NotNull  // Identifies this organization  across multiple systems

  @Min("0") @Max("1") @Doco("GLN identifier, [DA] EAN-nummer")
  @Definition("An identifier - identifies some entity uniquely and unambiguously. Typically this is used for business identifiers.")
  private GLNIdentifier EANID;  // GLN identifier, [DA] EAN-nummer

  @Min("0") @Max("1") @Doco("[DA] SOR-id")
  @Definition("An identifier - identifies some entity uniquely and unambiguously. Typically this is used for business identifiers.")
  private SORIdentifier SORID;  // [DA] SOR-id

  @Min("0") @Max("1") @Doco("[DA] Organisationsenheds-id som specificeret af FK-ORG")
  @Definition("An identifier - identifies some entity uniquely and unambiguously. Typically this is used for business identifiers.")
  private KombitOrgIdentifier KOMBITORGID;  // [DA] Organisationsenheds-id som specificeret af FK-ORG

  @Min("0") @Max("1") @Doco("[DA] Ydernummer")
  @Definition("Identifier for the organization that is used to identify the organization across multiple disparate systems.")
  private Identifier Ydernummer;  // [DA] Ydernummer

  @Min("0") @Max("1") @Doco("VAT identification number, [DA] CVR-nummer")
  @Definition("An identifier - identifies some entity uniquely and unambiguously. Typically this is used for business identifiers.")
  private CVRIdentifier CVRID;  // VAT identification number, [DA] CVR-nummer

  @Min("0") @Max("1") @Doco("[DA] Kommunekode")
  @Definition("Identifier for the organization that is used to identify the organization across multiple disparate systems.")
  private Identifier Kommunekode;  // [DA] Kommunekode

  @Min("0") @Max("1") @Doco("[DA] Regionskode")
  @Definition("Identifier for the organization that is used to identify the organization across multiple disparate systems.")
  private Identifier Regionskode;  // [DA] Regionskode

  @Min("0") @Max("1") @Doco("[DA] Producent Id")
  @Definition("An identifier - identifies some entity uniquely and unambiguously. Typically this is used for business identifiers.")
  private ProducentId ProducentID;  // [DA] Producent Id

  @Min("0") @Max("1") @Doco("Name used for the organization")
  @Definition("A name associated with the organization.")
  private String name;  // Name used for the organization

  @Min("0") @Max("*") @Doco("A contact detail for the organization")
  @Definition("A contact detail for the organization.")
  private List<ContactPoint> telecoms = new ArrayList<>();  // A contact detail for the organization

  @Min("0") @Max("*") @Doco("An address for the organization")
  @Definition("An address for the organization.")
  private List<Address> addresses = new ArrayList<>();  // An address for the organization

  @Min("0") @Max("1") @Doco("The organization of which this organization forms a part")
  @Definition("The organization of which this organization forms a part.")
  private Reference partOf;  // The organization of which this organization forms a part

  @Min("0") @Max("*") @Doco("Contact for the organization for a certain purpose")
  @Definition("Contact for the organization for a certain purpose.")
  private List<BackboneElement> contacts = new ArrayList<>();  // Contact for the organization for a certain purpose

  @Min("0") @Max("*") @Doco("Technical endpoints providing access to services operated for the organization")
  @Definition("Technical endpoints providing access to services operated for the organization.")
  private List<Reference> endpoints = new ArrayList<>();  // Technical endpoints providing access to services operated for the organization


  /**
   * Parameter-less constructor.
   *
   */
  public DkCoreOrganization() {
  }

  /**
   * Construct an instance of the object, and fill out all the fixed values 
   *
   */
  public DkCoreOrganization(IWorkerContext context) {
    workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance src = builder.buildPEInstance(CANONICAL_URL, builder.createResource(CANONICAL_URL, false));
    load(src);
  }

  /**
   * Populate an instance of the object based on this source object 
   *
   */
  public static DkCoreOrganization fromSource(IWorkerContext context, Organization source) {
    DkCoreOrganization theThing = new DkCoreOrganization();
    theThing.workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance src = builder.buildPEInstance(CANONICAL_URL, source);
    theThing.load(src);
    return theThing;
  }


  public void load(PEInstance src) {
    clear();
    if (src.hasChild("id")) {
      id = ((IdType) src.child("id").asDataType()).getValue();
    }
    for (PEInstance item : src.children("extension")) {
      extensions.add((Extension) item.asDataType());
    }
    for (PEInstance item : src.children("modifierExtension")) {
      modifierExtensions.add((Extension) item.asDataType());
    }
    for (PEInstance item : src.children("identifier")) {
      identifiers.add((Identifier) item.asDataType());
    }
    if (src.hasChild("EAN-ID")) {
      EANID = GLNIdentifier.fromSource(src.child("EAN-ID"));
    }
    if (src.hasChild("SOR-ID")) {
      SORID = SORIdentifier.fromSource(src.child("SOR-ID"));
    }
    if (src.hasChild("KOMBIT-ORG-ID")) {
      KOMBITORGID = KombitOrgIdentifier.fromSource(src.child("KOMBIT-ORG-ID"));
    }
    if (src.hasChild("Ydernummer")) {
      Ydernummer = (Identifier) src.child("Ydernummer").asDataType();
    }
    if (src.hasChild("CVR-ID")) {
      CVRID = CVRIdentifier.fromSource(src.child("CVR-ID"));
    }
    if (src.hasChild("Kommunekode")) {
      Kommunekode = (Identifier) src.child("Kommunekode").asDataType();
    }
    if (src.hasChild("Regionskode")) {
      Regionskode = (Identifier) src.child("Regionskode").asDataType();
    }
    if (src.hasChild("ProducentID")) {
      ProducentID = ProducentId.fromSource(src.child("ProducentID"));
    }
    if (src.hasChild("name")) {
      name = ((StringType) src.child("name").asDataType()).getValue();
    }
    for (PEInstance item : src.children("telecom")) {
      telecoms.add((ContactPoint) item.asDataType());
    }
    for (PEInstance item : src.children("address")) {
      addresses.add((Address) item.asDataType());
    }
    if (src.hasChild("partOf")) {
      partOf = (Reference) src.child("partOf").asDataType();
    }
    for (PEInstance item : src.children("contact")) {
      contacts.add((BackboneElement) item.asElement());
    }
    for (PEInstance item : src.children("endpoint")) {
      endpoints.add((Reference) item.asDataType());
    }

  }

  /**
   * Build a instance of the underlying object based on this wrapping object 
   *
   */
  public Organization build(IWorkerContext context) {
    workerContext = context;
    return build();
  }

  /**
   * Build a instance of the underlying object based on this wrapping object 
   *
   */
  public Organization build() {
    Organization theThing = new Organization();
    PEBuilder builder = new PEBuilder(workerContext, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance tgt = builder.buildPEInstance(CANONICAL_URL, theThing);
    save(tgt, false);
    return theThing;
  }

  /**
   * Save this profile class into an existing resource (overwriting anything that 
   * exists in the profile) 
   *
   */
  public void save(IWorkerContext context, Organization dest, boolean nulls) {
    workerContext = context;
    PEBuilder builder = new PEBuilder(context, PEElementPropertiesPolicy.EXTENSION, true);
    PEInstance tgt = builder.buildPEInstance(CANONICAL_URL, dest);
    save(tgt, nulls);
  }

  public void save(PEInstance tgt, boolean nulls) {
    tgt.clear("id");
    if (id != null) {
      tgt.makeChild("id").data().setProperty("value", new IdType(id));
    }
    tgt.clear("extension");
    for (Extension item : extensions) {
      tgt.addChild("extension", item);
    }
    tgt.clear("modifierExtension");
    for (Extension item : modifierExtensions) {
      tgt.addChild("modifierExtension", item);
    }
    tgt.clear("identifier");
    for (Identifier item : identifiers) {
      tgt.addChild("identifier", item);
    }
    tgt.clear("EAN-ID");
    if (EANID != null) {
      EANID.save(tgt.makeChild("EAN-ID"), nulls);
    }
    tgt.clear("SOR-ID");
    if (SORID != null) {
      SORID.save(tgt.makeChild("SOR-ID"), nulls);
    }
    tgt.clear("KOMBIT-ORG-ID");
    if (KOMBITORGID != null) {
      KOMBITORGID.save(tgt.makeChild("KOMBIT-ORG-ID"), nulls);
    }
    tgt.clear("Ydernummer");
    if (Ydernummer != null) {
      tgt.addChild("Ydernummer", Ydernummer);
    }
    tgt.clear("CVR-ID");
    if (CVRID != null) {
      CVRID.save(tgt.makeChild("CVR-ID"), nulls);
    }
    tgt.clear("Kommunekode");
    if (Kommunekode != null) {
      tgt.addChild("Kommunekode", Kommunekode);
    }
    tgt.clear("Regionskode");
    if (Regionskode != null) {
      tgt.addChild("Regionskode", Regionskode);
    }
    tgt.clear("ProducentID");
    if (ProducentID != null) {
      ProducentID.save(tgt.makeChild("ProducentID"), nulls);
    }
    tgt.clear("name");
    if (name != null) {
      tgt.makeChild("name").data().setProperty("value", new StringType(name));
    }
    tgt.clear("telecom");
    for (ContactPoint item : telecoms) {
      tgt.addChild("telecom", item);
    }
    tgt.clear("address");
    for (Address item : addresses) {
      tgt.addChild("address", item);
    }
    tgt.clear("partOf");
    if (partOf != null) {
      tgt.addChild("partOf", partOf);
    }
    tgt.clear("contact");
    for (BackboneElement item : contacts) {
      tgt.addChild("contact", item);
    }
    tgt.clear("endpoint");
    for (Reference item : endpoints) {
      tgt.addChild("endpoint", item);
    }

  }

  public String getId() {
    return id;
  }

  public DkCoreOrganization setId(String value) {
    this.id = value;
    return this;
  }

  public boolean hasId() {
    return id != null;
  }

  /**
   * May be used to represent additional information that is not part of the basic 
   * definition of the resource. To make the use of extensions safe and manageable, 
   * there is a strict set of governance  applied to the definition and use of 
   * extensions. Though any implementer can define an extension, there is a set of 
   * requirements that SHALL be met as part of the definition of the extension.
   *
   */
  public List<Extension> getExtensions() {
    if (extensions == null) { extensions = new ArrayList<>(); }
    return extensions;
  }

  public boolean hasExtensions() {
    return extensions != null && !extensions.isEmpty();
  }

  public Extension addExtension() {
    Extension theThing = new Extension();
    getExtensions().add(theThing);
    return theThing;
  }

  public boolean hasExtension(Extension item) {
    return hasExtensions() && extensions.contains(item);
  }

  public void removeExtension(Extension item) {
    if (hasExtension(item)) {
      extensions.remove(item);
    }
  }


  /**
   * May be used to represent additional information that is not part of the basic 
   * definition of the resource and that modifies the understanding of the element 
   * that contains it and/or the understanding of the containing element's 
   * descendants. Usually modifier elements provide negation or qualification. To 
   * make the use of extensions safe and manageable, there is a strict set of 
   * governance applied to the definition and use of extensions. Though any 
   * implementer is allowed to define an extension, there is a set of requirements 
   * that SHALL be met as part of the definition of the extension. Applications 
   * processing a resource are required to check for modifier extensions.
   *
   * 
   *
   * Modifier extensions SHALL NOT change the meaning of any elements on Resource or 
   * DomainResource (including cannot change the meaning of modifierExtension 
   * itself).
   *
   */
  public List<Extension> getModifierExtensions() {
    if (modifierExtensions == null) { modifierExtensions = new ArrayList<>(); }
    return modifierExtensions;
  }

  public boolean hasModifierExtensions() {
    return modifierExtensions != null && !modifierExtensions.isEmpty();
  }

  public Extension addModifierExtension() {
    Extension theThing = new Extension();
    getModifierExtensions().add(theThing);
    return theThing;
  }

  public boolean hasModifierExtension(Extension item) {
    return hasModifierExtensions() && modifierExtensions.contains(item);
  }

  public void removeModifierExtension(Extension item) {
    if (hasModifierExtension(item)) {
      modifierExtensions.remove(item);
    }
  }


  /**
   * Identifier for the organization that is used to identify the organization across 
   * multiple disparate systems.
   *
   */
  public List<Identifier> getIdentifiers() {
    if (identifiers == null) { identifiers = new ArrayList<>(); }
    return identifiers;
  }

  public boolean hasIdentifiers() {
    return identifiers != null && !identifiers.isEmpty();
  }

  public Identifier addIdentifier() {
    Identifier theThing = new Identifier();
    getIdentifiers().add(theThing);
    return theThing;
  }

  public boolean hasIdentifier(Identifier item) {
    return hasIdentifiers() && identifiers.contains(item);
  }

  public void removeIdentifier(Identifier item) {
    if (hasIdentifier(item)) {
      identifiers.remove(item);
    }
  }


  /**
   * An identifier - identifies some entity uniquely and unambiguously. Typically 
   * this is used for business identifiers.
   *
   */
  public GLNIdentifier getEANID() {
    if (EANID == null) { EANID = new GLNIdentifier(); }
    return EANID;
  }

  public DkCoreOrganization setEANID(GLNIdentifier value) {
    this.EANID = value;
    return this;
  }
  public boolean hasEANID() {
    return EANID != null;
  }

  /**
   * An identifier - identifies some entity uniquely and unambiguously. Typically 
   * this is used for business identifiers.
   *
   */
  public SORIdentifier getSORID() {
    if (SORID == null) { SORID = new SORIdentifier(); }
    return SORID;
  }

  public DkCoreOrganization setSORID(SORIdentifier value) {
    this.SORID = value;
    return this;
  }
  public boolean hasSORID() {
    return SORID != null;
  }

  /**
   * An identifier - identifies some entity uniquely and unambiguously. Typically 
   * this is used for business identifiers.
   *
   */
  public KombitOrgIdentifier getKOMBITORGID() {
    if (KOMBITORGID == null) { KOMBITORGID = new KombitOrgIdentifier(); }
    return KOMBITORGID;
  }

  public DkCoreOrganization setKOMBITORGID(KombitOrgIdentifier value) {
    this.KOMBITORGID = value;
    return this;
  }
  public boolean hasKOMBITORGID() {
    return KOMBITORGID != null;
  }

  /**
   * Identifier for the organization that is used to identify the organization across 
   * multiple disparate systems.
   *
   */
  public Identifier getYdernummer() {
    if (Ydernummer == null) { Ydernummer = new Identifier(); }
    return Ydernummer;
  }

  public DkCoreOrganization setYdernummer(Identifier value) {
    this.Ydernummer = value;
    return this;
  }
  public boolean hasYdernummer() {
    return Ydernummer != null;
  }

  /**
   * An identifier - identifies some entity uniquely and unambiguously. Typically 
   * this is used for business identifiers.
   *
   */
  public CVRIdentifier getCVRID() {
    if (CVRID == null) { CVRID = new CVRIdentifier(); }
    return CVRID;
  }

  public DkCoreOrganization setCVRID(CVRIdentifier value) {
    this.CVRID = value;
    return this;
  }
  public boolean hasCVRID() {
    return CVRID != null;
  }

  /**
   * Identifier for the organization that is used to identify the organization across 
   * multiple disparate systems.
   *
   */
  public Identifier getKommunekode() {
    if (Kommunekode == null) { Kommunekode = new Identifier(); }
    return Kommunekode;
  }

  public DkCoreOrganization setKommunekode(Identifier value) {
    this.Kommunekode = value;
    return this;
  }
  public boolean hasKommunekode() {
    return Kommunekode != null;
  }

  /**
   * Identifier for the organization that is used to identify the organization across 
   * multiple disparate systems.
   *
   */
  public Identifier getRegionskode() {
    if (Regionskode == null) { Regionskode = new Identifier(); }
    return Regionskode;
  }

  public DkCoreOrganization setRegionskode(Identifier value) {
    this.Regionskode = value;
    return this;
  }
  public boolean hasRegionskode() {
    return Regionskode != null;
  }

  /**
   * An identifier - identifies some entity uniquely and unambiguously. Typically 
   * this is used for business identifiers.
   *
   */
  public ProducentId getProducentID() {
    if (ProducentID == null) { ProducentID = new ProducentId(); }
    return ProducentID;
  }

  public DkCoreOrganization setProducentID(ProducentId value) {
    this.ProducentID = value;
    return this;
  }
  public boolean hasProducentID() {
    return ProducentID != null;
  }

  /**
   * A name associated with the organization.
   *
   */
  public String getName() {
    return name;
  }

  public DkCoreOrganization setName(String value) {
    this.name = value;
    return this;
  }

  public boolean hasName() {
    return name != null;
  }

  /**
   * A contact detail for the organization.
   *
   */
  public List<ContactPoint> getTelecoms() {
    if (telecoms == null) { telecoms = new ArrayList<>(); }
    return telecoms;
  }

  public boolean hasTelecoms() {
    return telecoms != null && !telecoms.isEmpty();
  }

  public ContactPoint addTelecom() {
    ContactPoint theThing = new ContactPoint();
    getTelecoms().add(theThing);
    return theThing;
  }

  public boolean hasTelecom(ContactPoint item) {
    return hasTelecoms() && telecoms.contains(item);
  }

  public void removeTelecom(ContactPoint item) {
    if (hasTelecom(item)) {
      telecoms.remove(item);
    }
  }


  /**
   * An address for the organization.
   *
   */
  public List<Address> getAddresses() {
    if (addresses == null) { addresses = new ArrayList<>(); }
    return addresses;
  }

  public boolean hasAddresses() {
    return addresses != null && !addresses.isEmpty();
  }

  public Address addAddress() {
    Address theThing = new Address();
    getAddresses().add(theThing);
    return theThing;
  }

  public boolean hasAddress(Address item) {
    return hasAddresses() && addresses.contains(item);
  }

  public void removeAddress(Address item) {
    if (hasAddress(item)) {
      addresses.remove(item);
    }
  }


  /**
   * The organization of which this organization forms a part.
   *
   */
  public Reference getPartOf() {
    if (partOf == null) { partOf = new Reference(); }
    return partOf;
  }

  public DkCoreOrganization setPartOf(Reference value) {
    this.partOf = value;
    return this;
  }
  public boolean hasPartOf() {
    return partOf != null;
  }

  /**
   * Contact for the organization for a certain purpose.
   *
   */
  public List<BackboneElement> getContacts() {
    if (contacts == null) { contacts = new ArrayList<>(); }
    return contacts;
  }

  public boolean hasContacts() {
    return contacts != null && !contacts.isEmpty();
  }

  public boolean hasContact(BackboneElement item) {
    return hasContacts() && contacts.contains(item);
  }

  public void removeContact(BackboneElement item) {
    if (hasContact(item)) {
      contacts.remove(item);
    }
  }


  /**
   * Technical endpoints providing access to services operated for the organization.
   *
   */
  public List<Reference> getEndpoints() {
    if (endpoints == null) { endpoints = new ArrayList<>(); }
    return endpoints;
  }

  public boolean hasEndpoints() {
    return endpoints != null && !endpoints.isEmpty();
  }

  public Reference addEndpoint() {
    Reference theThing = new Reference();
    getEndpoints().add(theThing);
    return theThing;
  }

  public boolean hasEndpoint(Reference item) {
    return hasEndpoints() && endpoints.contains(item);
  }

  public void removeEndpoint(Reference item) {
    if (hasEndpoint(item)) {
      endpoints.remove(item);
    }
  }




  public void clear() {
    id = null;
    extensions.clear();
    modifierExtensions.clear();
    identifiers.clear();
    EANID = null;
    SORID = null;
    KOMBITORGID = null;
    Ydernummer = null;
    CVRID = null;
    Kommunekode = null;
    Regionskode = null;
    ProducentID = null;
    name = null;
    telecoms.clear();
    addresses.clear();
    partOf = null;
    contacts.clear();
    endpoints.clear();

  }

}
